﻿using filecopy.io.Item;
using filecopy.io.Path;
using System;

namespace filecopy.io.Container
{
    public class FsContainer : IContainer
    {
        internal string nowpath { get; set; } = string.Empty;
        internal string[] filter_tags { get; set; } = new string[0];

        public string NowPath => nowpath;

        public FsContainer()
        {
        }

        public void To(string path)
        {
            this.nowpath = path;
        }

        public void SetFilterTags(params string[] tags)
        {
            this.filter_tags = tags;
        }
        public IEnumerable<IFileCopyItem> FindItems(params string[] name_tags)
        {
            foreach (var file in Directory.GetFiles(nowpath))
            {
                if (name_tags.Where(t=> !file.Contains(t, StringComparison.OrdinalIgnoreCase)).Count() == 0)
                {
                    if (filter_tags.Where(t => !file.Contains(t, StringComparison.OrdinalIgnoreCase)).Count() == 0)
                    {

                        yield return new FsItem(this, file);
                    }
                }
            }
        }
        public IEnumerable<IFileCopyItem> FindItems()
        {
            foreach (var file in Directory.GetFiles(nowpath))
            {
                if (filter_tags.Where(t => !file.Contains(t, StringComparison.OrdinalIgnoreCase)).Count() == 0)
                {
                    yield return new FsItem(this, file);
                }
            }
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public string[] Ls()
        {
            throw new NotImplementedException();
        }

        public IFileCopyPath TakeNowPath()
        {
            throw new NotImplementedException();
        }
    }
}
